package com.vench.teddy.controller;

import com.vench.teddy.common.Result;
import com.vench.teddy.pojo.bo.DirectMessageBO;
import lombok.AllArgsConstructor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author:vench
 * @Date:2024-09-13 23:31
 */
@RestController
@RequestMapping("mq")
@AllArgsConstructor
public class MQController {

    private final RabbitTemplate rabbitTemplate;

    @PostMapping("sendOneMsg")
    public Result sendOneMsg(@RequestBody @Validated DirectMessageBO directMessageBO){
        rabbitTemplate.convertAndSend(directMessageBO.getExchange(), directMessageBO.getRouting(), directMessageBO.getContent());
        return Result.success("消息发送成功");
    }

}
